package com.ruoyi.web.controller.system;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.WGoodsRecords;
import com.ruoyi.system.service.IWGoodsRecordsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 物品库存记录Controller
 * 
 * @author ruoyi
 * @date 2021-12-05
 */
@RestController
@RequestMapping("/system/goodrecords")
public class WGoodsRecordsController extends BaseController
{
    @Autowired
    private IWGoodsRecordsService wGoodsRecordsService;

    /**
     * 查询物品库存记录列表
     */
    @PreAuthorize("@ss.hasPermi('system:records:list')")
    @GetMapping("/list")
    public TableDataInfo list(WGoodsRecords wGoodsRecords)
    {
        startPage();
        List<WGoodsRecords> list = wGoodsRecordsService.selectWGoodsRecordsList(wGoodsRecords);
        return getDataTable(list);
    }

    /**
     * 导出物品库存记录列表
     */
    @PreAuthorize("@ss.hasPermi('system:records:export')")
    @Log(title = "物品库存记录", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(WGoodsRecords wGoodsRecords)
    {
        List<WGoodsRecords> list = wGoodsRecordsService.selectWGoodsRecordsList(wGoodsRecords);
        ExcelUtil<WGoodsRecords> util = new ExcelUtil<WGoodsRecords>(WGoodsRecords.class);
        return util.exportExcel(list, "物品库存记录数据");
    }

    /**
     * 获取物品库存记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:records:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(wGoodsRecordsService.selectWGoodsRecordsById(id));
    }

    /**
     * 新增物品库存记录
     */
    @PreAuthorize("@ss.hasPermi('system:records:add')")
    @Log(title = "物品库存记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WGoodsRecords wGoodsRecords)
    {
        return toAjax(wGoodsRecordsService.insertWGoodsRecords(wGoodsRecords));
    }

    /**
     * 修改物品库存记录
     */
    @PreAuthorize("@ss.hasPermi('system:records:edit')")
    @Log(title = "物品库存记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WGoodsRecords wGoodsRecords)
    {
        return toAjax(wGoodsRecordsService.updateWGoodsRecords(wGoodsRecords));
    }

    /**
     * 删除物品库存记录
     */
    @PreAuthorize("@ss.hasPermi('system:records:remove')")
    @Log(title = "物品库存记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(wGoodsRecordsService.deleteWGoodsRecordsByIds(ids));
    }
}
